﻿using AutoUpdate.Work;
using System;
using System.Threading;
using System.Windows.Forms;

namespace AutoUpdate
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        public Form1(string version)
        {
            InitializeComponent();
            this.versionLable.Text = version;
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            UpdateWork updateWork = new UpdateWork();
            updateWork.InfoEvent += UpdateNotify;
            updateWork.DownloadEvent += DownloadProgressChanged;
            ThreadStart start = () => updateWork.StartUpdate();
            new Thread(start).Start();
        }

        private void UpdateNotify(string msg)
        {
            this.Invoke(new EventHandler(delegate
            {
                this.textBox1.AppendText(msg+"\r\n");
            }));
            
        }

        private void DownloadProgressChanged(int progress)
        {
            this.Invoke(new EventHandler(delegate
            {
                this.progressBar1.Value = progress;
            }));
            
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
